<?php
/*
 * 推荐位置索引
 */

if(!defined('IN_SITE') || !defined('IN_ADMIN')) {
	exit('Access Denied');
}

$op = in_array($op, array("add", "del", "edit", "editsave", "list")) ? $op : 'list';

switch ($op) {
	case 'add':
		if($recomlistadd)
		{
			$lname = $fontnum = $width = $height = '';
			$lname = trim($_POST['lname']);
			$fontnum = trim($_POST['fontnum']);
			$width = trim($_POST['width']);
			$height = trim($_POST['height']);
			$filedir = trim($_POST['filedir']);

			if($recomlistadd && !empty($lname)) {
				$query = $db->query("INSERT INTO {$tablepre}recomlist(lname, fontnum, width, height, filedir) VALUES('$lname', '$fontnum', '$width', '$height', '$filedir')");
				if($query) showMessage("新推荐位置添加成功！", "?action=recommendlist&op=list");
			}
		}
		break;
		
	case 'del':
//		$lid = $_POST['lid'];
//		if(isset($lid) && !empty($lid)) {
//			$lidcount = count($lid);
//			for ($i=0; $i<$lidcount; $i++) {
//				$query = $db->query("DELETE FROM {$tablepre}recomlist WHERE lid='$lid[$i]'");
//			}
//			if($query) showMessage("删除成功！", "?action=recommendlist&op=list");
//		}
		showMessage("目前不允许删除操作！");
		break;
		
	case 'edit':
		$lid = $_GET['lid'];
		$query = $db->query("SELECT lid, lname, fontnum, width, height, filedir FROM {$tablepre}recomlist WHERE lid='$lid'");
		$recommendlist = $db->fetch_array($query);
		break;
		
	case 'editsave':
		$lid = $_POST['lid'];
		$lname = trim($_POST['lname']);
		$fontnum = trim($_POST['fontnum']);
		$width = trim($_POST['width']);
		$height = trim($_POST['height']);
		$filedir = trim($_POST['filedir']);
		
		if(isset($lid) && !empty($lid) && !empty($lname)) {
			$query = $db->query("UPDATE {$tablepre}recomlist SET lname='$lname', fontnum='$fontnum', width='$width', height='$height', filedir='$filedir' WHERE lid='$lid'");
			if($query) showMessage("修改成功！", "?action=recommendlist&op=list");
		}
		break;
		
	case 'list':
		$query = $db->query("SELECT lid, lname, fontnum, width, height, filedir FROM {$tablepre}recomlist ORDER BY lid ASC");
		while ($row = $db->fetch_array($query)) {
			$recomlist[]=$row;
		}
		break;
}
include admin_tpl("recommendlist");
?>